#include "../../../shared/dal/user_dao.hpp"
#include "../../../shared/dal/odb_factory.hpp"
#include "../../../entity/user.hxx"
#include "logger.hpp"
#include "user-odb.hxx"
#include <gflags/gflags.h>
#include <iostream>
#include <string>

DEFINE_bool(run_mode, false, "程序的运行模式: false-调试 true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

void insert(shared::dal::UserDao& userDao)
{
    auto user1 = std::make_shared<entity::User>("uid1", "1111", "小美", "15599992222");
    auto user2 = std::make_shared<entity::User>("uid2", "2222", "大美", "15566667777");
    userDao.insert(user1);
    userDao.insert(user2);
}

void updateByuserId(shared::dal::UserDao& userDao)
{
    auto user = userDao.selectByUserId("uid1");
    user->setDscription("我是小美");
    userDao.update(user);
}

void updateByNickname(shared::dal::UserDao& userDao)
{
    auto user = userDao.selectByUserId("uid2");
    user->setNickname("小帅");
    userDao.update(user);
}

void updateByPhone(shared::dal::UserDao& userDao)
{
    auto user = userDao.selectByUserId("uid2");
    user->setPhone("14725836999");
    userDao.update(user);
}

void selectUsers(shared::dal::UserDao& userDao)
{
    std::vector<std::string> userIdList = {"uid1", "uid2"};
    auto users = userDao.selectMultiUsers(userIdList);
    for(auto& user : users) {
        std::cout << user->userId() << " " << user->nickname() << "\n";
    } 
}

int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    shared::init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    auto db = shared::dal::ODBFactory::create("root", "weng9244", "127.0.0.1", "chat_system", "utf8", 0, 1);
    
    shared::dal::UserDao user(db);

    // insert(user);
    // updateByuserId(user);
    // updateByNickname(user);
    updateByPhone(user);
    // selectUsers(user);
    return 0;
}